#include <bits/stdc++.h>
using namespace std;

const int N = 2e5+5;
int t,n,a[N];
long long f[N];

int check(int x,int y){
	if(a[x] != a[y]) return 0;
	return a[x];
}


int main(){
	freopen("color.in","r",stdin);
	freopen("color.out","w",stdout);
	scanf("%d",&t);
	while(t--){
		memset(f,0,sizeof(f));
		memset(a,0,sizeof(a));
		scanf("%d",&n);
		for(int i = 1; i <= n; ++i)
			scanf("%d",&a[i]);
		for(int i = 1; i <= n; ++i){
			for(int j = 0; j < i-1; ++j){
				f[i-1] = max(f[i-1],f[j]+check(i,j));
			}
			for(int j = 0; j < i-1; ++j){
				f[j] = f[j]+check(i,i-1);
			}
		}
		long long res = 0;
		for(int i = 0; i <= n-1; ++i){
			res = max(res,f[i]);
		}
		printf("%lld\n",res);
	}
	return 0;
}
